//
//  UIViewController+Hud.m
//  TQServy
//
//  Created by 寒竹子 on 15/5/15.
//  Copyright (c) 2015年 Hangang. All rights reserved.
//  +Hud

#import "UIViewController+Hud.h"
#import <objc/runtime.h>
#import "MBProgressHUD.h"

@implementation UIViewController (hud)

/**
 * @brief  显示Hud
 *
 * @param
 *
 * @return
 */
- (void)showHudInView:(UIView *)view hint:(NSString *)hint
{
    // 创建Hud
    MBProgressHUD * progressHud = [[MBProgressHUD alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
    progressHud.tag = 2001;
    progressHud.labelFont = [UIFont systemFontOfSize:15.0f];
    progressHud.labelColor = [UIColor whiteColor];
    progressHud.labelText = hint;
    
    progressHud.animationType = MBProgressHUDAnimationFade;
    progressHud.removeFromSuperViewOnHide = YES;
    [view addSubview:progressHud];
    [progressHud show:YES];
}

/**
 * @brief  显示成功或者失败的信息 delay (s)
 *
 * @param
 *
 * @return
 */
- (void)showHudWithHint:(NSString *)hint delay:(int)timeDelay
{
    // 创建Hud
    MBProgressHUD * progressHud = [[MBProgressHUD alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
    progressHud.tag = 2001;
    progressHud.labelFont = [UIFont systemFontOfSize:15.0f];
    progressHud.labelColor = [UIColor whiteColor];
    progressHud.labelText = hint;
    progressHud.mode = MBProgressHUDModeText; // 只显示文字
    progressHud.animationType = MBProgressHUDAnimationFade;
    progressHud.removeFromSuperViewOnHide = YES;
    [[UIApplication sharedApplication].keyWindow addSubview:progressHud];
    [progressHud show:YES];
    
    [progressHud hide:YES afterDelay:timeDelay];
}

/**
 * @brief  隐藏Hud
 *
 * @param
 *
 * @return
 */
- (void)hideHud
{
    MBProgressHUD * progressHud = (MBProgressHUD *)[self.view viewWithTag:2001];
    
    [progressHud hide:YES];
}

@end
